<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>sort排序</title>
  </head>
  <body>
    <script>
      var arr = [1, 21, 2123, 41, 57, 6777];
      // arr.sort;
      // console.log(arr); //没有传回调函数
      //直接调用sort 会根据ASSCI码来进行排序

      arr.sort(function (a, b) {
        return a - b;
        // console.dir(arr.sort);
      });
      console.log(arr);

      var arr = [
        { name: "张三", age: 20 },
        { name: "张三", age: 23 },
        { name: "张三", age: 22 },
      ];
      arr.sort(function (a, b) {
        return b.age - a.age;
      });
      console.log(arr);
    </script>
  </body>
</html>
